package com.hz.ruoyilgorder.config;

import com.hz.rouyigonggong.domain.LgSellerOrder;
import com.hz.rouyigonggong.domain.dto.LgSellerOrderDTO;

/**
 * @version 1.0
 * @Author yzw
 * @Date 2025/3/5 18:19
 * @注释  dto转换为实体类
 */
public class LgSellerOrderConverter {


    public static LgSellerOrderDTO toDto(LgSellerOrder order) {
        if (order == null) {
            return null;
        }

        LgSellerOrderDTO dto = new LgSellerOrderDTO();
        dto.setId(order.getId());
        dto.setOrderNumber(order.getOrderNumber());
        dto.setSellerId(order.getSellerId());
        dto.setSellerName(order.getSellerName());
        dto.setSellerContact(order.getSellerContact());
        dto.setGoodsId(order.getGoodsId());
        dto.setGoodsName(order.getGoodsName());
        dto.setProvidedWeight(order.getProvidedWeight());
        dto.setGoodsQuantity(order.getGoodsQuantity());
        dto.setGoodsUnit(order.getGoodsUnit());
        dto.setStorageDays(order.getStorageDays());
        dto.setOrigin(order.getOrigin());
        dto.setOriginX(order.getOriginX());
        dto.setOriginY(order.getOriginY());
        dto.setColdStorageId(order.getColdStorageId());
        dto.setDestination(order.getDestination());
        dto.setDestinationX(order.getDestinationX());
        dto.setDestinationY(order.getDestinationY());
        dto.setDistance(order.getDistance());
        dto.setWarehouseType(order.getWarehouseType());
        dto.setFreightCost(order.getFreightCost());
        dto.setEstimatedPrice(order.getEstimatedPrice());
        dto.setFinalGoodsPrice(order.getFinalGoodsPrice());
        dto.setFinalFreightPrice(order.getFinalFreightPrice());
        dto.setDepositRequired(order.getDepositRequired());
        dto.setPaymentAmount(order.getPaymentAmount());
        dto.setDepositPaid(order.getDepositPaid());

        // Setting additional mapping fields
        dto.setCktype("");  // Map or add appropriate value here if necessary
        dto.setWarehouseAddress("");  // Map or add appropriate value here if necessary

        return dto;
    }

    public static LgSellerOrder toEntity(LgSellerOrderDTO dto) {
        if (dto == null) {
            return null;
        }

        LgSellerOrder order = new LgSellerOrder();
        order.setId(dto.getId());
        order.setOrderNumber(dto.getOrderNumber());
        order.setSellerId(dto.getSellerId());
        order.setSellerName(dto.getSellerName());
        order.setSellerContact(dto.getSellerContact());
        if(dto.getGoodsName()!=null){
            order.setGoodsId(Integer.parseInt(dto.getSubGoodsName()));
        }
        order.setProvidedWeight(dto.getProvidedWeight());
        order.setGoodsQuantity(dto.getGoodsQuantity());
        order.setGoodsUnit(dto.getGoodsUnit());
        order.setStorageDays(dto.getStorageDays());
        order.setOrigin(dto.getOrigin());
        order.setOriginX(dto.getOriginX());
        order.setOriginY(dto.getOriginY());
        order.setColdStorageId(dto.getColdStorageId());
        order.setDestination(dto.getDestination());
        order.setDestinationX(dto.getDestinationX());
        order.setDestinationY(dto.getDestinationY());
        order.setDistance(dto.getDistance());
        if(dto.getCktype()!=null){
            order.setWarehouseType(Integer.parseInt(dto.getCktype()));
        }
        order.setFreightCost(dto.getFreightCost());
        order.setEstimatedPrice(dto.getEstimatedPrice());
        order.setFinalGoodsPrice(dto.getFinalGoodsPrice());
        order.setFinalFreightPrice(dto.getFinalFreightPrice());
        order.setDepositRequired(dto.getDepositRequired());
        order.setPaymentAmount(dto.getPaymentAmount());
        order.setDepositPaid(dto.getDepositPaid());
        order.setCreateBy(dto.getCreateBy());
        order.setUpdateBy(dto.getUpdateBy());
        order.setCreateTime(dto.getCreateTime());
        order.setUpdateTime(dto.getUpdateTime());
        order.setSubId(dto.getSubWarehouseId());
        order.setColdStorageId(dto.getWarehouseId());
        return order;
    }
}
